package cn.yunyichina.provider.framework.utils;

/**
 * 获取调用服务名和方法名
 *
 * @author zhangkewen
 */
public class CallDataUtils {

    /**
     * 获取方法名
     *
     * @param method
     * @return
     */
    public static String getMethod(String method) {
        String[] arrMethod = method.split("\\.");
        int len = arrMethod.length;
        String methodName = "";

        if (len == 4) {
            methodName = arrMethod[3] + arrMethod[2].substring(0, 1).toUpperCase() + arrMethod[2].substring(1);
        } else {
            for (int i = 2; i < len; i++) {
                String methodPart = arrMethod[i];
                if (i != len - 1 && methodPart.length() > 0) {
                    methodPart = methodPart.substring(0, 1).toUpperCase() + methodPart.substring(1);
                    methodName = methodName + methodPart;
                } else {
                    methodName = methodPart + methodName;
                }
            }
        }

        return methodName;
    }

    /**
     * 获取服务名字
     *
     * @param method
     * @return
     */
    public static String getServiceName(String method) {
        String[] methodToken = method.split("\\.");
        String servicename = methodToken[2].toLowerCase() + "ServiceImpl";
        return servicename;
    }

    public static String getSecondServiceName(String method) {
        String servicename = "";
        String[] methodToken = method.split("\\.");

        if (methodToken.length >= 4) {
            servicename = methodToken[2].toLowerCase() + methodToken[3].substring(0, 1).toUpperCase() + methodToken[3].substring(1).toLowerCase() + "ServiceImpl";
        }

        return servicename;
    }

}
